/* GUI CONVERTED from recwup.p (converter v1.76) Tue Oct  2 12:13:51 2001 */
/* recwup.p   - REPETITIVE   PROGRAM TO CREATE CUM WORKORDERS IN ADVANCE      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.7.1.8 $                                                       */
/*                                                                            */
/* THE PURPOSE IS TO AVOID CREATING CUM WORKORDERS INTERACTIVELY              */
/*                                                                            */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 11/03/94   BY: WUG *GN98*                */
/* REVISION: 7.3      LAST MODIFIED: 03/29/95   BY: dzn *F0PN*                */
/* REVISION: 8.5      LAST MODIFIED: 05/12/95   BY: pma *J04T*                */
/* REVISION: 8.5      LAST MODIFIED: 09/05/95   BY: srk *J07G*                */
/* REVISION: 8.5      LAST MODIFIED: 06/03/96   BY: jym *G1VW*                */
/* REVISION: 8.5      LAST MODIFIED: 06/20/96   BY: taf *J0VG*                */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 07/25/00   BY: *N0GD* Ganga Subramanian  */
/* REVISION: 9.1      LAST MODIFIED: 08/18/00   BY: *N0MC* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/28/00   BY: *N0P5* Mudit Mehta        */
/* Revision: 1.7.1.7  BY: Jean Miller           DATE: 09/18/01  ECO: *N12P*   */
/* $Revision: 1.7.1.8 $  BY: Robin McCarthy      DATE: 10/01/01  ECO: *P025*  */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*V8:ConvertMode=Report                                                       */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE recwup_p_1 "Start Eff"
/* MaxLen: Comment: */

&SCOPED-DEFINE recwup_p_3 "End Eff"
/* MaxLen: Comment: */

&SCOPED-DEFINE recwup_p_4 "End Effective"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define buffer womstr for wo_mstr.
define variable cumwo_lot like wo_lot.
define variable end_wo_eff as date label {&recwup_p_4}.
define variable line like wo_line.
define variable line1 like wo_line label {t001.i}.
define variable lot like wo_lot.
define variable lot1 like wo_lot label {t001.i}.
define variable part like wo_part.
define variable part1 like wo_part label {t001.i}.
define variable site like wo_site.
define variable site1 like wo_site label {t001.i}.
define variable todays_date as date.
define variable there_is_wip as logical.

define variable ptstatus like pt_status no-undo.
define variable msgdesc like msg_desc no-undo.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
lot                  colon 20
   lot1                 colon 45
   part                 colon 20
   part1                colon 45
   site                 colon 20
   site1                colon 45
   line                 colon 20
   line1                colon 45
   skip(1)
   end_wo_eff           colon 32
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* ADD THE FOLLOWING FORM STATEMENT TO REPORT RECORDS WITH */
/* RESTRICTED ITEM STATUS CODES                            */
FORM /*GUI*/ 
   wo_lot
   wo_site
   msg_desc format "x(79)"
with STREAM-IO /*GUI*/  frame restricted width 132 no-attr-space down.

/* SET EXTERNAL LABELS */
setFrameLabels(frame restricted:handle).

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.
if not available mfc_ctrl or mfc_logical = false then do:
   /* Module has not been enabled in Control File Maintenance */
   {pxmsg.i &MSGNUM=5119 &ERRORLEVEL=3}
   message.
   message.
   leave.
end.

end_wo_eff = today.

mainloop:
repeat:

   todays_date = today.

   if lot1 = hi_char then lot1 = "".
   if part1 = hi_char then part1 = "".
   if site1 = hi_char then site1 = "".
   if line1 = hi_char then line1 = "".

   update
      lot
      lot1
      part
      part1
      site
      site1
      line
      line1
      end_wo_eff
   with frame a.

   if end_wo_eff = ? then do:
      /* Invalid Date */
      {pxmsg.i &MSGNUM=27 &ERRORLEVEL=3}
      next-prompt end_wo_eff with frame a.
      undo, retry.
   end.

   bcdparm = "".
   {mfquoter.i lot              }
   {mfquoter.i lot1             }
   {mfquoter.i part             }
   {mfquoter.i part1            }
   {mfquoter.i site             }
   {mfquoter.i site1            }
   {mfquoter.i line             }
   {mfquoter.i line1            }
   {mfquoter.i end_wo_eff       }

   if lot1 = "" then lot1 = hi_char.
   if part1 = "" then part1 = hi_char.
   if site1 = "" then site1 = hi_char.
   if line1 = "" then line1 = hi_char.

   /*SITE (RANGE-OF) SECURITY CHECK*/
   if not batchrun then do:
      {gprun.i ""gpsirvr.p""
         "(input site, input site1, output return_int)"}
      if return_int = 0 then do:
         next-prompt site with frame a.
         undo mainloop, retry mainloop.
      end.
   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   {mfphead.i}

   mainloop:
   for each wo_mstr no-lock
      where wo_type = "c"
        and wo_status <> "c"
        and wo_lot >= lot and wo_lot <= lot1
        and wo_part >= part and wo_part <= part1
        and wo_site >= site and wo_site <= site1
        and wo_line >= line and wo_line <= line1
        and wo_due_date = end_wo_eff
        and wo_nbr = ""
   use-index wo_type_part
   by wo_site by wo_part by wo_line by wo_due_date by wo_lot:

      there_is_wip = no.

      /* DO NOT ALLOW CREATION OF A CUMULATIVE WORK ORDER WHERE      */
      /* THE PART STATUS IS RESTRICTED AGAINST REPETITVE.            */
      /* THE # IN PT_STATUS IS USED TO DEFINE AN ITEM STATUS CODE,   */
      /* NO # IS FOR INVENTORY STATUS CODE.                          */
      find pt_mstr where pt_part = wo_part no-lock no-error.

      if available pt_mstr then do:

         assign
            ptstatus = pt_status
            substring(ptstatus,9,1) = "#".

         if can-find(isd_det where isd_status = ptstatus
                               and isd_tr_type = "ADD-RE")
         then do:

            /* Unable to create wo, Restricted proc for code */
            {pxmsg.i &MSGNUM=4871 &ERRORLEVEL=1 &MSGBUFFER=msgdesc}

            display
               wo_lot
               wo_site
               msgdesc @ msg_desc
            with frame restricted STREAM-IO /*GUI*/ .

            down 1 with frame restricted.

            next mainloop.

         end. /* RESTRICTED ITEM STATUS CODE */

      end. /* AVAILABLE pt_mstr */

      for each wr_route no-lock
         where wr_lot = wo_lot
      break by wr_op:

         if (not first(wr_op) and wr_qty_inque <> 0)
            or wr_qty_outque <> 0
            or wr_qty_rejque <> 0
         then do:
            there_is_wip = yes.
            leave.
         end.

      end.

      if there_is_wip then do:

         /*FIND CUM ORDER.  CREATE IT IF IT DOESN'T EXIST*/
         {gprun.i ""regetwo.p""
            "(input wo_site,
              input wo_part,
              input wo_due_date + 1,
              input wo_line,
              input wo_routing,
              input wo_bom_code,
              output cumwo_lot)"}

         if cumwo_lot = ? then do:

            {gprun.i ""recrtwo.p""
               "(input wo_site,
                 input wo_part,
                 input wo_due_date + 1,
                 input wo_line,
                 input wo_routing,
                 input wo_bom_code,
                 output cumwo_lot)"}

            do for womstr with frame f-a:

               find womstr where wo_lot = cumwo_lot no-lock.

               setFrameLabels(frame f-a:handle). /* SET EXTERNAL LABELS */

               display
                  wo_site
                  wo_part
                  wo_line
                  wo_routing
                  wo_bom_code
                  wo_rel_date column-label {&recwup_p_1}
                  wo_due_date column-label {&recwup_p_3}
                  wo_lot
               with width 132 STREAM-IO /*GUI*/ .

            end. /* do for womstr */

         end. /* if cumwo_lot = ? */

      end. /* if there_is_wip */

   end. /* mainloop: for each wo_mstr */

   {mfrtrail.i}

end. /* mainloop */
